<?php

namespace app\admin\model;

use think\Model;


class Bets extends Model
{

    

    // 表名
    protected $name = 'bets';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'addtime_text',
        'game_text',
        'status_text',
        'role_text'
    ];

    public function user()
    {
        return $this->hasOne('User','id','user_id');
    }
    
    public function getGameList()
    {
        return ['lol' => __('Game lol'), 'pvp' => __('Game pvp'), 'dota2' => __('Game dota2')];
    }     

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
    }     

    public function getRoleList()
    {
        return ['0' => __('Role 0'), '1' => __('Role 1')];
    }     


    public function getAddtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['addtime']) ? $data['addtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getGameTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['game']) ? $data['game'] : '');
        $list = $this->getGameList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRoleTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['role']) ? $data['role'] : '');
        $list = $this->getRoleList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setAddtimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


}
